Skip to content

fix: emit diagnostic for unsupported extern fn in const evaluation instead of panicking#9811

Merged
orizi merged 1 commit intomainfrom
orizi/03-31-fix_unsupported_extern_fn_in_const
Apr 1, 2026
Merged

fix: emit diagnostic for unsupported extern fn in const evaluation instead of panicking#9811
orizi merged 1 commit intomainfrom
orizi/03-31-fix_unsupported_extern_fn_in_const

Conversation

@orizi
Copy link
Copy Markdown
Collaborator

@orizi orizi commented Mar 31, 2026

Summary

Replace unreachable panic with proper error reporting when user-defined extern const functions are used in constant expressions.


Type of change

Please check one:

  • Bug fix (fixes incorrect behavior)
  • New feature
  • Performance improvement
  • Documentation change with concrete technical impact
  • Style, wording, formatting, or typo-only change

Why is this change needed?

The code previously used unreachable!() when encountering user-defined extern const functions in constant expressions, which would cause the compiler to panic. This is incorrect behavior as user-defined extern functions should be handled gracefully with a proper diagnostic error rather than crashing the compiler.


What was the behavior or documentation before?

When a user-defined extern const function was used in a constant expression, the compiler would panic with an "Unexpected extern function in constant lowering" message.


What is the behavior or documentation after?

The compiler now properly reports error E2127 "This expression is not supported as constant" when encountering user-defined extern const functions in constant expressions, providing a clear diagnostic message to the user instead of crashing.


Related issue or discussion (if any)

Fixes #9799


Additional context

The fix includes a test case that verifies the proper error reporting behavior when extern const fn f() -> felt252 nopanic; is called within a constant declaration.


Note

Low Risk
Small, localized change to const-eval error handling plus a regression test; main risk is only altered diagnostics/behavior for previously panicking edge cases.

Overview
Fixes a compiler panic during constant evaluation: when a constant expression calls a user-defined extern const fn that isn’t one of the corelib-supported const-eval externs, the evaluator now returns UnsupportedConstant (E2127) instead of hitting an unreachable!() and crashing.

Adds a regression test covering extern const fn f() -> felt252 used in a const initializer, asserting the new diagnostic output.

Written by Cursor Bugbot for commit 968be14. This will update automatically on new commits. Configure here.

Copy link
Copy Markdown
Collaborator Author

orizi commented Mar 31, 2026

@reviewable-StarkWare
Copy link
Copy Markdown

This change is Reviewable

Copy link
Copy Markdown
Contributor

@eytan-starkware eytan-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@eytan-starkware reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on TomerStarkware).

Copy link
Copy Markdown
Collaborator

@TomerStarkware TomerStarkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@TomerStarkware made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on orizi).

@orizi orizi changed the base branch from orizi/03-31-fix_non_type_numeric_literal_suffix to graphite-base/9811 April 1, 2026 09:17
@orizi orizi force-pushed the orizi/03-31-fix_unsupported_extern_fn_in_const branch from 6ef9148 to 968be14 Compare April 1, 2026 09:19
@orizi orizi force-pushed the graphite-base/9811 branch from fca4f70 to 8dd8779 Compare April 1, 2026 09:19
@orizi orizi changed the base branch from graphite-base/9811 to main April 1, 2026 09:19
@orizi orizi enabled auto-merge April 1, 2026 09:20
@orizi orizi added this pull request to the merge queue Apr 1, 2026
Merged via the queue into main with commit 5248475 Apr 1, 2026
105 checks passed
@orizi orizi deleted the orizi/03-31-fix_unsupported_extern_fn_in_const branch April 1, 2026 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Compiler panic in semantic pass: unreachable!() in evaluate_function_call for user-defined extern const fn

4 participants